const path = require('path')
// webpack-node-externals 是一个 Webpack 插件/工具，专门用于 Node.js 环境下的打包优化
// 主要作用是告诉 Webpack 在打包时排除 node_modules 目录中的模块（即不将这些第三方模块打包到最终的 bundle 中）
const nodeExternals = require('webpack-node-externals')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const { node } = require('webpack')
// const HtmlWebpackPlugin = require('html-webpack-plugin')
// const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
// const TerserPlugin = require('terser-webpack-plugin')
// const webpack = require('webpack')

const webpackconfig = {
    target:'node',
    mode:'development',
    entry:{
        server: path.join(__dirname,'./src/index.js')
    },
    output:{
        filename:'[name].bundle.js',
        path:path.join(__dirname,'./dist'),
    },
    devtool:'eval-source-map',
    module:{
        rules:[
            {
                test:/\.(js|jsx)$/,
                use:{
                    loader:'babel-loader'
                },
                exclude:[path.join(__dirname,'/node_modules')]
            },
            {
            }
        ]
    },
    externals:[nodeExternals()],
    plugins:[
        new CleanWebpackPlugin()
    ],
    node:{ 
        console:true,
        global:true,
        process:true,
        Buffer:true,
        __filename:true,
        __dirname:true,
        setImmediate:true,
        path:true
    }
}

module.exports = webpackconfig